import React from 'react'
import Taro from '@tarojs/taro'
import { AtTabBar  } from 'taro-ui'

class TabBar extends React.Component{

  constructor () {
    super(...arguments)
    this.state = {
      current: this.props.current
    }
  }

  handleClick (value) {
    if (value==this.state.current){
      return
    }
    this.setState({current: value})
    switch (value) {
      case 0:
          Taro.redirectTo({url: '/pages/index/index'})
          break;
      case 1:
          Taro.redirectTo({url: '/pages/userCenter/userCenter'})
          break;       
      default:
          break;
    }   
  }

    render(){
      return (
        <AtTabBar fixed tabList={[
              {title:'主页', iconType: 'home'},
              {title:'个人中心',iconType: 'user'}]}
            onClick={this.handleClick.bind(this)}
            current={this.state.current}/>
      )
    }
  }
  
export {TabBar}